from random import choice
from os.path import exists
from os import getenv
from sys import argv
file = argv[-1]
if file == "-lf" or file == "/lf" or file == "LF":
    file = argv[-2]
    LF = 1
if file == "-crlf" or file == "/crlf" or file == "CRLF":
    file = argv[-2]
    LF = 0
if len(argv) == 1:
    try:
        file = input("请输入输出文件路径\nCtrl+Z(可能需要回车)表示不输出\n>")
        a = file.split("%")
        if len(a) > 1:
            for i in range(1,len(a),2):
                a[i] = getenv(a[i])
        "".join(a)

    except EOFError:
        file = getenv("appdata")+"\\cache.txt"

if exists(file):
    b = True
    while b:
        c = input("警告：覆盖文件? (y/n)")
        if c not in ["y","n"]:
            print("错误：请输入y(是)或者n(否)")
            continue
        b = False
    if c == "n":
        print("请修改命令行参数再运行该程序")
        input("回车退出")
        exit(4)
p = []
a = ""
p.extend("1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM")
b = True
while b:
    try:
        n = eval(input("密码长度: "))
    except: 
        print("错误：你输入的不是数字")
        continue
    b = False
b = True
while b:
    c = input("包含符号? (y/n)")
    if c not in ["y","n"]:
        print("错误：请输入y(是)或者n(否)")
        continue
    b = False
if c == "y":
    p.extend("!@#$%^&*()")
b = True
while b:
    try:
        c = eval(input("生成数量："))
    except: 
        print("错误：你输入的不是数字")
        continue
    b = False
b = []
print()
with open(file,"w") as f:
    for j in range(c):
        for i in range(n):
            a += choice(p)
        print(a)
        f.write(a)
        if LF:
            f.write("\n")
        else:
            f.write("\r\n")
        a = ""

print()
print()
input("回车退出")
exit(0)